package tech.summerly.weather.component.adapter

import android.support.v7.widget.RecyclerView
import android.text.Html
import android.view.ViewGroup
import kotlinx.android.synthetic.main.item_pollutants_detail.view.*
import tech.summerly.weather.R
import tech.summerly.weather.data.bean.RealTime
import tech.summerly.weather.util.ViewHolder

class PollutantsAdapter(private val realTime: RealTime) : RecyclerView.Adapter<ViewHolder>() {

    companion object {
        private val NAME = listOf("细颗粒物", "可吸入颗粒物", "二氧化硫", "二氧化氮", "一氧化碳", "臭氧")
        private val TERM = listOf("PM2.5", "PM10", "S0<sub><small>2</small></sub>", "NO<sub><small>2</small></sub>", "CO", "O<sub><small>3</small></sub>")
        private val KEY = listOf("pm25", "pm10", "so2", "no2", "co", "o3")
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = ViewHolder.createView(R.layout.item_pollutants_detail, parent)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return NAME.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) = with(holder.itemView) {
        textTerm.text = Html.fromHtml(TERM[position])
        textName.text = NAME[position]
        val value: Number = when (position) {
            0 -> realTime.pm25
            1 -> realTime.pm10
            2 -> realTime.so2
            3 -> realTime.no2
            4 -> realTime.co
            5 -> realTime.o3
            else -> 0
        }
        textValue.text = value.toString()
    }


}